<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="流转Id">
            <a-input  v-decorator="['flowId', validatorRules.flowId]"  />
          </a-form-item>
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="流转来源">
            <a-input placeholder="请输入流转来源" v-decorator="['sourceRef', validatorRules.sourceRef ]"  />
          </a-form-item>
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="流程状态列名">
            <a-input placeholder="流转目标" v-decorator="['targetRef', validatorRules.targetRef]"  />
          </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="流程状态列名">
          <a-input placeholder="流转目标" v-decorator="['targetRef', validatorRules.targetRef]"  />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="表达式">
          <a-input placeholder="表达式" v-decorator="['conditionExpression']"   />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="表达式spring bean(全路径)">
          <a-input placeholder="表达式spring bean(全路径)" v-decorator="['beanName']"   />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="节点类型">
          <j-dict-select-tag  v-decorator="[ 'flowJumpType', {}]" :trigger-change="true"   dictCode="flow_jump_type"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="排序">
          <a-input placeholder="排序" v-decorator="['sort']"  />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import {getAction, httpAction} from '@/api/manage'
import pick from 'lodash.pick'

export default {
    name: "ExtActProcessGatewayFormModal",
    props:{
      processId:{
        type: String,
        default: ''
      }
    },
    data () {
      return {
        title:"操作",
        visible: false,
        relationCodeReadonly:true,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        formTypeValue:"1",
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          edit: "/api/erpmng/act/process/extActProcessNode/gatewayEdit",
        },
      }
    },
    created () {
    },
    mounted(){
    },
    methods: {
      genDefaultCode(){
        var tabeName = this.form.getFieldValue("flowId");
        if(tabeName!=null&&tabeName!=''&&tabeName!=undefined){
          var sourceRef = this.form.getFieldValue("sourceRef");
          if(sourceRef==null||sourceRef==''||sourceRef==undefined){
            var params = {
              tabeName:tabeName
            };//查询条件
            getAction(this.url.genDefaultCode,params).then((res)=>{
              if(res.success){
                var flowCode = res.result;
                this.form.setFieldsValue({sourceRef:flowCode});
              }
            })
          }
        }else{
          this.$message.success("请填写表名！");
        }
      },
      handleFormTableName(e){
        var value = e.target.value;
        console.log(value);
        if(value!=null&&value!=''&&value!=undefined){
          var flowCode = "onl_"+value;
          this.form.setFieldsValue({sourceRef:flowCode});
        }else{
          this.form.setFieldsValue({sourceRef:""});
        }
      },
      handleDesignFormTableName(e){
        var value = e.target.value;
        console.log(value);
        if(value!=null&&value!=''&&value!=undefined){
          var flowCode = "desform_"+value;
          this.form.setFieldsValue({sourceRef:flowCode});
        }else{
          this.form.setFieldsValue({sourceRef:""});
        }
      },
      handleFormTypeChange(value){
        this.formTypeValue = value;
        //this.model.listenerValue = "";
        this.form.setFieldsValue({flowId:""});
        this.form.setFieldsValue({sourceRef:""});
      },
      add () {
        this.edit({formType:"1",formDealStyle:"default",targetRef:"bpm_status"});
      },
      edit (record) {
        this.form.resetFields();
        this.formTypeValue = record.formType;
          this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'sourceRef','id','processId','flowId','beanName','conditionExpression','sort','targetRef'))
		  //时间格式化

        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            httpurl+=this.url.edit;
            method = 'put';
            let formData = Object.assign(this.model, values);
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>

<style scoped>

</style>